package org.jeecg.modules.api.controller.music.songs;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.api.vo.songs.SongsDetailVo;
import org.jeecg.modules.music.entity.MusSong;
import org.jeecg.modules.music.service.IMusAlbumSongListService;
import org.jeecg.modules.music.service.IMusArtistService;
import org.jeecg.modules.music.service.IMusSongService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

@Slf4j
@Api(tags="音乐系统")
@RestController
@RequestMapping("api/mus/")
public class SongsCenterAPIController {


    @Autowired
    private IMusSongService musSongService;

    @Autowired
    private IMusArtistService musArtistService;

    @Autowired
    private IMusAlbumSongListService musAlbumSongListService;


    @ApiOperation("API-歌曲接口-获取歌手单曲 /artists")
    @RequestMapping(value = "/artists", method = RequestMethod.GET)
    public Result queryArtistSong(@RequestParam(name="id",required=true)String id){

        Map<String, Object> resultMap = new HashMap<>();
        List<SongsDetailVo> songs = musSongService.querySongsByArtistId(id);
        resultMap.put("hotSongs",songs);
        return Result.ok(resultMap);

    }
    @ApiOperation("API-歌曲接口-获取歌曲详情")
    @RequestMapping(value = "/song/detail", method = RequestMethod.GET)
    public Result queryDetailSong(@RequestParam(name="ids",required=true)String songIds){

        Map<String, Object> resultMap = new HashMap<>();

        String[] ids = songIds.split(",");
        List<SongsDetailVo> songs = musSongService.queryAPISongDetail(ids);
        resultMap.put("songs",songs);
        return Result.ok(resultMap);

    }


    @ApiOperation("API-歌曲接口-获取歌词")
    @RequestMapping(value = "/lyric", method = RequestMethod.GET)
    public Result queryLyric(@RequestParam(name="id",required=true)String id){
        Map<String, Object> map = new HashMap<>();
        map.put("lrc",musSongService.queryLyric(id));
        return Result.ok(map);
    }

    @ApiOperation("API-歌曲接口-获取歌曲音频URL")
    @RequestMapping(value = "/song/url", method = RequestMethod.GET)
    public Result queryAudioUrl(@RequestParam(name="id",required=true)String id){
        Map<String, Object> map = new HashMap<>();
        map.put("mp3",musSongService.queryAudioFile(id));
        return Result.ok(map);
    }

    @ApiOperation("API-歌曲接口-获取相似歌曲")
    @RequestMapping(value = "/simi/song", method = RequestMethod.GET)
    public Result<Map<String,Object>> simpleSongs(@RequestParam(name="id",required=true)String id){
        MusSong song = musSongService.getById(id);
        Map<String,Object> map = new HashMap<>();
        if(song!=null){
            String singerId = song.getArtistId();
            String composer = song.getComposer();
            String lyricist  = song.getLyricist();
            List<SongsDetailVo> songs = musSongService.getSimilarSongs(id,singerId,composer,lyricist);
            map.put("songs",songs);
        }

        return Result.ok(map);
    }
}
